<?php
class ControllerAccountPassword extends AccountController {
	     
  	public function index() {	

    	$this->document->setTitle($this->_['heading_title']);
		$this->document->addScript('static/javascript/jquery/jquery.validate.js');
		
    	if ($this->request->isPost() && $this->validate()) {
			M('account/customer');
			
			$this->model_account_customer->editPassword($this->customer->getEmail(), $this->request->post['password']);
 
      		$this->session->set_flashdata('success', $this->_['text_success']);	  
	  		$this->redirect(US('account/account'));
    	}
		
      	$this->data['breadcrumbs'][] = array(
        	'text'      => $this->_['heading_title'],
			'href'      => US('account/password'),
        	'separator' => $this->_['text_separator']
      	);		
	
		$this->data['password'] = P('password');
		$this->data['confirm'] = P('confirm');

		$this->display('account/password.tpl');
  	}
  
  	protected function validate() {
		$p = true;
		
    	if ((utf8_strlen($this->request->post['password']) < 4) || (utf8_strlen($this->request->post['password']) > 20)) {
      		$this->setMessage('error_password', $this->_['error_password']);
			$p = false;
    	}

    	if ($this->request->post['confirm'] != $this->request->post['password']) {
      		$this->setMessage('error_confirm', $this->_['error_confirm']);
			$p = false;
    	}  
		return $p;
  	}
}
?>
